using System;
using System.Collections.Generic;
using System.Text;

namespace DiggTools
{
    /// <summary>
    /// Defines the filters that can be sorted on
    /// </summary>
    public enum SortFilter : int
    {
        /// <summary>
        /// The Date of promotion
        /// </summary>
        promoteDate = 0,

        /// <summary>
        /// The Date the story was submitted
        /// </summary>
        submitDate = 1,
    }

    /// <summary>
    /// SearchOptions contains all global options that can be applied to queries
    /// </summary>
    public class SearchOptions
    {

        /// <summary>
        /// Initialize all private data
        /// </summary>
        public SearchOptions()
        {
            _count = -1;
            _offset = -1;
            _timestamp = new DateTime(1970, 1, 1, 0, 0, 0);
            _minDate = new DateTime(1970, 1, 1, 0, 0, 0);
            _maxDate = new DateTime(1970, 1, 1, 0, 0, 0);
            _sortFilter = "";
        }

        /// <summary>
        /// Set the number of stories to get
        /// </summary>
        /// <param name="count">The number of stories</param>
        public void SetCount( int count )
        {
            _count = count;
        }

        /// <summary>
        /// return the number of stories to ger
        /// </summary>
        /// <returns>The number of stories</returns>
        public int GetCount()
        {
            return _count;
        }

        /// <summary>
        /// Set the offset of the search
        /// </summary>
        /// <param name="offset">The story that the list starts at. With an offset of 0, the list includes the ten most recently submitted stories. With an offset of 10, the list would return the next 10 most recently submitted stories.</param>
        public void SetOffset(int offset)
        {
            _offset = offset;
        }

        /// <summary>
        /// Get the offset of the seach
        /// </summary>
        /// <returns>The offset</returns>
        public int GetOffset()
        {
            return _offset;
        }

        /// <summary>
        /// Set the timestamp for the query
        /// </summary>
        /// <param name="timestamp">specifies results with this timestamp</param>
        public void SetTimestamp(DateTime timestamp)
        {
            _timestamp = timestamp;
        }

        /// <summary>
        /// Gets the timestamp for this query
        /// </summary>
        /// <returns></returns>
        public DateTime GetTimestamp()
        {
            return _timestamp;
        }

        /// <summary>
        /// Sets the minimum date for the query
        /// </summary>
        /// <param name="mindate">The minimum date for the query</param>
        public void SetMinDate(DateTime mindate)
        {
            _minDate = mindate;
        }

        /// <summary>
        /// Gets the minimum date for the query
        /// </summary>
        /// <returns>The minimum date for the query</returns>
        public DateTime GetMinDate()
        {
            return _minDate;
        }

        /// <summary>
        /// Sets the maximum date for the query
        /// </summary>
        /// <param name="maxdate">The maximum date for the query</param>
        public void SetMaxDate(DateTime maxdate)
        {
            _maxDate = maxdate;
        }

        /// <summary>
        /// Gets the maximum date for the query
        /// </summary>
        /// <returns>The max date</returns>
        public DateTime GetMaxDate()
        {
            return _maxDate;
        }
        
        /// <summary>
        /// Sets the sorting filter. First select what to sort on and then specify ascending or descending
        /// </summary>
        /// <param name="theFilter">The filter is an item that can be sorted on</param>
        /// <param name="descending">Specified to sort to be descenting (true) or ascending (false)</param>
        public void SetSortFilter(SortFilter theFilter, bool descending)
        {
            if (descending)
            {
                _sortFilter = getFilterName((int)theFilter) + "-desc";
            }
            else
            {
                _sortFilter = getFilterName((int)theFilter) + "-asc";
            }
        }

        /// <summary>
        /// Get the sort filter for this query
        /// </summary>
        /// <returns>The sort filter</returns>
        public String GetSortFilter()
        {
            return _sortFilter;
        }

        /// <summary>
        /// Gets the name of the filter for the corresponding integer
        /// </summary>
        /// <param name="theFilter">the integer that represents the filter</param>
        /// <returns>The name of the filter</returns>
        private String getFilterName(int theFilter)
        {
            String theFilterName = "";
            switch (theFilter)
            {
                case 0:
                    theFilterName = "promote_date";
                    break;
                case 1:
                    theFilterName = "submit_date";
                    break;

            }

            return theFilterName;
        }

        private int _count;
        private int _offset;
        private DateTime _timestamp;
        private DateTime _minDate;
        private DateTime _maxDate;
        private String _sortFilter;
	
    }

    
}
